package cn.edu.xaut.servlet;

import cn.edu.xaut.db.ConnDB;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

import java.sql.*;

@WebServlet("/loginProgress")
public class LoginProgress extends HttpServlet {

    public LoginProgress() {
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        doGet(request, response);
    }


    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


        // 获取参数
        String username = request.getParameter("username");
        String password = request.getParameter("password");

        // 查询语句
        String sql = "select * from dbmis.tb_admin where username = '" + username + "' and password = '" + password + "'";
        try {
            ResultSet rs = ConnDB.queryByPstmt(sql);   // 连接数据库并查询

            // 成功：可以登陆，进入管理过程
            // 失败：重定向到login.jsp
            rs.last();
            PrintWriter out = response.getWriter();
            out.println(rs.getRow());

            ConnDB.close(); // 释放资源
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
